package edu.ucsd.cse135.gas.action.applicant;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.logic.Degree;
import edu.ucsd.cse135.gas.logic.applicant.Applicant;
import edu.ucsd.cse135.gas.resources.Constants;

public class ConfirmationAction extends Action {

	public ConfirmationAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
		
		/** Get applicant object **/
		
		Applicant applicant = (Applicant)request.getSession().getAttribute("applicant");
		
		/** Write applicant information to database **/
		
		applicant.writeToDatabase();
		
		/** Get degree list **/
		
		ArrayList<Degree> degreeList = (ArrayList<Degree>)request.getSession().getAttribute("degrees");
		
		/** Write all degrees in the list to the database **/
		
		for(int i = 0; i < degreeList.size(); i++)
		{
			Degree degree = degreeList.get(i);
			degree.setApplicantId(applicant.getApplicantId());
			degree.writeToDatabase();
		}
	
		return mapping.findForward(Constants.SUCCESS);
		
	}

}
